<?php

use yii\helpers\Url;
use yii\bootstrap\Alert;
use backend\widgets\GridView;
use yii\widgets\LinkPager;
use backend\models\Tweet;

$this->title = "渠道详情";
?>
<link href="../../css/ThePass.css" rel="stylesheet">
<script type="text/javascript" src="https://cdn.bootcss.com/zclip/1.1.2/jquery.zclip.js"></script>
<style type="text/css">
    th{text-align:center !important;}
</style>

<div class="RightCenter clear">
    <div class="RightTime">
        <div class="Time">
            <h3>渠道详情:<?php echo $channel['username'].'('.$channel['id'].')';?></h3>
        </div>
    </div>
    <div class="Read_date" style="margin-top:20px;margin-bottom: 5px;height:60px;">
        <ul>
            <li class="Read_LisJ">
                <div class="Seek">
                    <input type="text" class="form-control AppIN" id="exampleInputAmount" placeholder="搜索书籍名称" value="<?php echo isset($params['name']) ? $params['name'] : '';?>">
                    <button type="button" class="btn btn-primary SS">搜索</button>
                </div>
            </li>
            <li style="float: right;">
                <div style="margin-right: 30%">
                    共 <?php echo $pagination->totalCount; ?>条数据
                </div>
            </li>
        </ul>
    </div>
    <?php
    if (Yii::$app->getSession()->hasFlash('success')) {
        echo Alert::widget([
            'options' => [
                'class' => 'alert-success', //这里是提示框的class
                'style' => 'width:96%;margin:0 auto;',
            ],
            'body' => Yii::$app->getSession()->getFlash('success'), //消息体
        ]);
    }
    if (Yii::$app->getSession()->hasFlash('error')) {
        echo Alert::widget([
            'options' => [
                'class' => 'alert-error',
                'style' => 'width:96%;margin:0 auto;',
            ],
            'body' => Yii::$app->getSession()->getFlash('error'),
        ]);
    }
    ?>
    <?php
    echo GridView::widget([
        'layout' => "{items}",
        'dataProvider' => $dataProvider,
        'tableOptions' => ['class' => 'Atable my_ta_ble'],
        'rowOptions' => ['class' => 'TR'],
        'columns' => [
            [
                'label' => '推广编号',
                'attribute' => 'tweet_sn',
            ],
            [
                'label' => '推广平台',
                'value' => function ($data) 
                {
                    $platform = '其他';
                    switch ($data['platform']){
                        case 1:
                            $platform = '微信';
                            break;
                        case 2:
                            $platform = '微博';
                            break;
                        case 3:
                            $platform = 'APP';
                            break;
                        default :
                            break;
                    }
                    return $platform;
                }
            ],
            [
                'label' => '书籍名称',
                'attribute' => 'novel_name',
            ],
            [
                'label' => '充值总额(元)',
//                'attribute' => 'pay_cnt',
                'value' => function($data){
                    $res = Tweet::getChargeSum($data['tweet_sn']);
                    return $res['money'];
                }
            ],
            [
                'label' => '充值笔数(次)',
                'value' => function($data){
                    $res = Tweet::getChargeSum($data['tweet_sn']);
                    return $res['cnt'];
                }
            ],
            [
                'label' => '收入(阅币)',
                'value' => function($data){
                    $res = Tweet::getConsumeSum($data['tweet_sn']);
                    return $res['money'];
                }
            ],
            [
                'label' => '阅币笔数',
                'value' => function($data){
                    $res = Tweet::getConsumeSum($data['tweet_sn']);
                    return $res['cnt'];
                }
            ],
            [
                'class' => 'yii\grid\ActionColumn',
                'header' => '操作', //template
                'template' => "{getLinks}",
                'buttons' => [
                    'getLinks' => function ($url, $data, $key) {
//                        if (Yii::$app->user->can('user.user.consume')) {
                            return "<a class='tw_right_QDxq' data-id='".$data['id']."' href='#'>查看\获取统计链接</a>";
//                        }
                    },
                ],
            ],
        ],
    ]);
            ?>
    <div style="float: right;margin-right: 1.7%;">
        <?php echo LinkPager::widget(['pagination' => $pagination]) ?>
    </div>
</div>


<div class="button_QDxq" style="display: none;">
    <h4>查看\获取统计链接 <i class="glyphicon glyphicon-remove modal_botI"></i></h4>
    <ul class="button_QDxq_ul">
        <li>
            <span class="button_QDxq_ul_span button_QDxq_ul_span1">复制</span>
            <span class="button_QDxq_ul_div">
                网站首页：<textarea spellcheck="false">https://www.baidu.com/</textarea>
            </span>
        </li>

        <li>
            <span class="button_QDxq_ul_span">复制</span>
            <span class="button_QDxq_ul_div">
                网站首页：<textarea spellcheck="false">https://www.baidu.com/</textarea>
            </span>
        </li>

        <li>
            <span class="button_QDxq_ul_span">复制</span>
            <span class="button_QDxq_ul_div">
                网站首页：<textarea spellcheck="false">https://www.baidu.com/</textarea>
            </span>
        </li>	   			


        <li>
            <span class="button_QDxq_ul_span">复制</span>
            <span class="button_QDxq_ul_div">
                网站首页：<textarea spellcheck="false">https://www.baidu.com/</textarea>
            </span>
        </li>

        <li>
            <span class="button_QDxq_ul_span">复制</span>
            <span class="button_QDxq_ul_div">
                网站首页：<textarea spellcheck="false">https://www.baidu.com/</textarea>
            </span>
        </li>


        <li>
            <span class="button_QDxq_ul_span">复制</span>
            <span class="button_QDxq_ul_div">
                网站首页：<textarea spellcheck="false">https://www.baidu.com/</textarea>
            </span>
        </li>

        <li>
            <span class="button_QDxq_ul_span">复制</span>
            <span class="button_QDxq_ul_div">
                网站首页：<textarea spellcheck="false">https://www.baidu.com/</textarea>
            </span>
        </li>

        <li>
            <span class="button_QDxq_ul_span">复制</span>
            <span class="button_QDxq_ul_div">
                网站首页：<textarea spellcheck="false">https://www.baidu.com/</textarea>
            </span>
        </li>

    </ul>

</div>

<div class="bonbeijing_FZ">
    复制成功
</div>

<div class="bonbeijing"></div>

<script>
    $(".tw_right_QDxq").click(function () {
        $(".button_QDxq").show()
        $(".bonbeijing").show()
        $("body").css("overflow", "hidden")
    })

    $(".modal_botI").click(function () {
        $(".button_QDxq").hide()
        $(".bonbeijing").hide()
        $("body").css("overflow", "auto")
    })

    /*	搜索*/
    $(".SS").click(function(){
        var name = $("#exampleInputAmount").val()
        if(name != ''){
            location.href="/admin/channel-info?id=<?php echo $channel['id']?>&name="+name
        }else{
            location.href="/admin/channel-info?id=<?php echo $channel['id']?>"
        }
    })

    /*复制*/
    for (var i = 0; i < $(".button_QDxq_ul_span").length; i++) {
        $(".button_QDxq_ul_span").eq(i).click(function () {
            var Url2 = $(this).next().find("textarea")
            Url2.select(); // 选择对象
            document.execCommand("Copy"); // 执行浏览器复制命令
            $(".bonbeijing_FZ").fadeIn()
            setTimeout(function () {
                $(".bonbeijing_FZ").fadeOut()
            }, 800);
        })
    }

</script>